
package com.dy.config;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.Data;

/**
 * @Description:基础信息配置
 * @Date：2018年6月29日 @author： DongY
 * @version ：1.0 1.[2018年6月29日]CreatBy：dy
 */
@Data
public class CreatConfig {

	private String basePackage = "com.dy";

	private String modalPackage = basePackage + ".domain";

	private String webPackage = basePackage + ".web";

	private String serviePackage = basePackage + ".service";
	// 根据项目将错就错将serviceImpl改为了seviceImpl
	private String serviceImplPackage = basePackage + ".seviceImpl";

	private String mapperPackage = basePackage + ".repository";

	private String tableName;
	// 要生成的类名
	private String className;
	//
	private String author;
	// 主键名
	private String priKeyName;

	private String dbName;
	{
		InetAddress address;
		try {
			address = InetAddress.getLocalHost();
			author = address.getHostName() + "(" + address.getHostAddress() + ")";
			System.out.println(author);
		} catch (final UnknownHostException e) {

			e.printStackTrace();
		}
	}

	public void setBasePackage(final String basePackage) {
		// 暂时直接赋值，之后将默认值全部更改为null，为null则重新赋值
		// 另外需加初始化后回调函数
		this.basePackage = basePackage;
		modalPackage = basePackage + ".domain";
		webPackage = basePackage + ".web";
		serviePackage = basePackage + ".service";
		serviceImplPackage = basePackage + ".seviceImpl";
		mapperPackage = basePackage + ".repository";
	}

	public static void main(final String[] args) throws IOException {
		final CreatConfig config = new CreatConfig();
		System.out.println(config);
		final ObjectMapper mapper = new ObjectMapper();
		System.out.println(mapper.writeValueAsString(config));
		final CreatConfig config2 = mapper.readValue(new File("f://c.json"), CreatConfig.class);
		System.out.println(config2);
		System.out.println(Integer.class.getSimpleName());
	}
}
